package com.wonders.frame.repository;

import com.wonders.frame.entity.AuthDicType;
import com.wonders.frame.entity.AuthOrga;
import com.wonders.frame.repository.core.CoreRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface AuthDicTypeRepository extends CoreRepository<AuthDicType> {

    @Query("select d from AuthDicType d where code=:code and removed = 0 ")
    List<AuthDicType> checkUnique(@Param("code") String code);

    @Query("select d from AuthDicType d where type=:type and removed = 0 order by seq")
    List<AuthDicType> findByType(@Param("type") String type);

    @Query("select d from AuthDicType d where type=:type and code=:code and removed = 0 order by seq")
    List<AuthDicType> findAuthDicType(@Param("type") String type, @Param("code") String code);

    @Query("select d from AuthDicType d where code=:code and removed = 0 order by seq")
    List<AuthDicType> findAuthDicTypeByCode(@Param("code") String code);

    @Query("select d from AuthDicType d where removed = 0  order by d.seq")
    List<AuthDicType> getAllAuthDicType();

    @Query("select d from AuthDicType d where removed = 0  and id=:id ")
    AuthDicType getOneAuthDicTypeById(@Param("id") String id);

    @Query("select count(d.id) from AuthDicType d where d.parentId = :parentId and d.removed = 0 ")
    long getParentCount(@Param("parentId") String parentId);

    @Query("select count(d.id) from AuthDicType d where d.code = :code and d.removed = 0 ")
    long isUnique(@Param("code") String code);

    List<AuthDicType> findByParentIdAndRemoved(String id, Integer removed);

    List<AuthDicType> findByNameLikeAndRemoved(String dicName, Integer removed);

}
